﻿namespace Leo.MSATracert
{
    public class LinkTracertPrincipal
    {
        public const string HEADER_NAME = "X-Connection-Id";

        public LinkTracertPrincipal(string traceId)
        {
            this.RequestId = traceId;
            this.TokenCollection = new List<IApiToken>();
        }
         
        internal LinkTracertPrincipal(string traceId, IEnumerable<IApiToken> tokens) : this(traceId)
        {
            if (tokens != null)
            {
                foreach (IApiToken token in tokens)
                {
                    this.AddToken(token);
                }
            }
        }
         
        public string RequestId { get; set; }
         
        public string IPAddress { get; set; }
         
        public List<IApiToken> TokenCollection { get; }
         
        public IApiToken JsonWebToken
        {
            get
            {
                return this.TokenCollection.Find((IApiToken x) => x.Name == "Authorization");
            }
        } 

        public void AddToken(IApiToken token)
        {
            this.TokenCollection.Add(token);
        }
          
    }
}
